<?php

	if (!class_exists('ctl_category'))
	{
		require_once(CORE_DIR.'/admin/controller/goods/category.php');
	}

	class diamond_admin_cct_category extends ctl_category
	{
		function diamond_admin_cct_category()
		{
			parent::ctl_category();
			$this->template_dir = CORE_DIR.'/admin/view/';
		}

		function addNew($id=0)
		{
			$this->path[] = array('text'=>__('商品分类新增'));
			$objCat = &$this->system->loadModel('goods/productCat');
			$aCat = $objCat->get_cat_list(true);
			$aCatNull[] = array('cat_id'=>0,'cat_name'=>__('----无----'),'step'=>1);
			if(empty($aCat)){
				$aCat = $aCatNull;
			}else{
				$aCat = array_merge($aCatNull, $aCat);
			}
			$this->pagedata['catList'] = $aCat;
			$this->pagedata['gtypes'] = $objCat->getTypeList();
			$oGtype = &$this->system->loadModel('goods/gtype');
			$this->pagedata['gtype']['status'] = $oGtype->checkDefined();
			if($id){
				$aCat = $objCat->getFieldById($id);
				$this->pagedata['cat']['parent_id'] = $aCat['cat_id'];
				$this->pagedata['cat']['type_id'] = $aCat['type_id'];
				if ('true' == $aCat['disabled'])
				{
					$this->pagedata['forceDisabled'] = true;
				}
			}else{
				$aTmp = $oGtype->getDefault();
				$this->pagedata['cat']['type_id'] = $aTmp[0]['type_id'];
			}
			$this->pagedata['cat']['p_order'] = 0;

			/* alone add start */
			$disOption =array('false'=>'是','true'=>'否');
			$this->pagedata['disOption'] = $disOption;
			/* alone add end */
			$this->page(dirname(__FILE__).'/view/admin/product/category/info.html');
		}

		function edit($catid)
		{
			$this->path[] = array('text'=>__('商品分类编辑'));
			$objCat = &$this->system->loadModel('goods/productCat');
			$aCat = $objCat->getFieldById($catid);
			$aCat['addon'] = unserialize($aCat['addon']);
			$this->pagedata['cat'] = $aCat;			
			
			$aCat = $objCat->get_cat_list();
			$aCatNull[] = array('cat_id'=>0,'cat_name'=>__('----无----'),'step'=>1);
			$aCat = array_merge($aCatNull, $aCat);
			$this->pagedata['catList'] = $aCat;
			$this->pagedata['gtypes'] = $objCat->getTypeList();
			$oGtype = &$this->system->loadModel('goods/gtype');
			$this->pagedata['gtype']['status'] = $oGtype->checkDefined();
			
			/* alone add start */
			//裸钻定制默认分类
			$diamond_tpl_cat = $this->system->getConf('diamond.diamond_cat_tpl');
			$showChecked = ($diamond_tpl_cat == $catid)?true:false;
			$this->pagedata['showChecked'] = $showChecked;

			//有父类 且前台不显示 子类也强制为不显示
			if ($this->pagedata['cat']['parent_id'])
			{
				$row = $objCat->getFieldById($this->pagedata['cat']['parent_id']);
				if ('true'==$row['disabled']) 
				{								
					$this->pagedata['forceDisabled'] = true;
				}
			}
			$disOption =array('false'=>'是','true'=>'否');
			$this->pagedata['disOption'] = $disOption;
			/* alone add end */
			$this->page(dirname(__FILE__).'/view/admin/product/category/info.html');
		}
		
		function doAdd()
		{
			$objCat = &$this->system->loadModel('plugins/diamond/diamondCat');
			if ($objCat->addNew($_POST['cat']))
				$this->splash('success', 'index.php?ctl=goods/category&act=index', __( '保存成功' ));
			else
				$this->splash('failed', 'index.php?ctl=goods/category&act=index', __( '保存失败' ));
		}
	}
?>